GridheimCell
The Core Cell Component of the Resurrected Sheetster System π₯
Overviewβ
GridheimCell is the fundamental building block of the modernized Sheetster spreadsheet system. This React/TypeScript component transforms legacy JavaScript cell handling patterns into a professional, type-safe, RTK Query-powered spreadsheet cell.
Key Featuresβ
- Smart Cell Expansion - Cells automatically expand to show overflow text
- Hyperlink Support - Ctrl+Click behavior with security warnings
- Formula Integration - Seamless handling of formulas vs display values
- Keyboard Navigation - Enter, Delete, and typing-to-edit behavior
- Cell Selection - Professional click and double-click handling
- Validation Messages - Real-time error feedback and validation
- RTK Query Integration - Full CRUD operations with ThorAPI backend
- TypeScript Safety - Complete type coverage with ThorAPI models
Usageβ
import { GridheimCell } from '@/components/Gridheim';
import { Cell } from '@thor/model';
const MySpreadsheet = () => {
const sampleCell: Cell = {
id: 'cell-a1',
sheetId: 'sheet-1',
row: { rowIndex: 0 },
column: { colIndex: 0 },
stringValue: 'Hello Gridheim!',
};
return (
<GridheimCell
cell={sampleCell}
address="A1"
isSelected={true}
onCellUpdate={(cell) => console.log('Cell updated:', cell)}
onCellSelect={(cell) => console.log('Cell selected:', cell)}
/>
);
};
Propsβ
Prop | Type | Required | Description |
---|---|---|---|
cell | Cell | Yes | ThorAPI Cell model object |
address | string | Yes | Cell address (A1, B5, etc.) |
onCellUpdate | (cell: Cell) => void | No | Callback when cell is updated |
onCellSelect | (cell: Cell) => void | No | Callback when cell is selected |
isSelected | boolean | No | Whether the cell is currently selected |
isEditing | boolean | No | Whether the cell is in edit mode |
readonly | boolean | No | Whether the cell is readonly |
isSheetProtected | boolean | No | Whether the parent sheet is protected |
Legacy Pattern Modernizationβ
From cellHandle.js (2,000+ lines of JavaScript):
// Legacy Ajax-based cell updates
new Ajax.Request(url, {
method: 'POST',
postBody: value.value,
onSuccess: function(response) {
sheet.updateCellsFromJSON(response.responseText);
}
});
To Modern RTK Query:
const [updateCell] = useUpdateCellMutation();
const handleCellUpdate = async (cell: Cell) => {
try {
await updateCell(cell).unwrap();
// RTK Query automatically updates cache
} catch (error) {
showError(`Error updating cell: ${error.message}`);
}
};
Smart Cell Expansionβ
GridheimCell implements intelligent text overflow handling:
- Left-aligned text expands to the right into empty cells
- Right-aligned text expands to the left into empty cells
- Center-aligned text expands in both directions
- Protected cells prevent expansion
- Occupied cells block expansion
Formula Supportβ
The component seamlessly handles different cell content types:
- Text values - Direct string display
- Numeric values - Proper number formatting
- Formulas - Shows calculated result with formula editing support
- Hyperlinks - Clickable links with security validation
Keyboard Interactionsβ
Key | Behavior |
---|---|
Enter | Start editing or move to next cell |
Delete | Clear cell content |
F2 | Start editing in formula bar |
Escape | Cancel editing |
Ctrl+Click | Follow hyperlinks (with security prompt) |
Validation & Error Handlingβ
GridheimCell provides comprehensive validation:
- Formula syntax validation
- Data type validation
- Security validation for hyperlinks
- User-friendly error messages
- Graceful fallback for network errors
Integration with ThorAPIβ
Full integration with the ThorAPI backend system:
- Cell Model - Uses generated Cell TypeScript interface
- CellService - RTK Query service for CRUD operations
- Format Model - Cell formatting and styling support
- Formula Model - Formula definition and calculation
- Automatic caching - RTK Query handles data synchronization
Performance Optimizationsβ
- Memoized rendering for unchanged cells
- Debounced updates to prevent excessive API calls
- Smart re-rendering only when necessary
- Efficient DOM updates using React's virtual DOM
Accessibilityβ
- ARIA labels for screen readers
- Keyboard navigation support
- High contrast mode compatibility
- Focus management for better UX
Browser Compatibilityβ
- Modern browsers - Chrome, Firefox, Safari, Edge
- Mobile support - Touch-friendly interactions
- Responsive design - Adapts to different screen sizes
Related Componentsβ
- GridheimSheet - Container for multiple cells
- GridheimFormulaBar - Formula editing interface
- GridheimFullDemo - Complete integration demo
Technical Specificationsβ
- Language: TypeScript 4.5+
- Framework: React 18+
- State Management: RTK Query
- Backend Integration: ThorAPI generated services
- CSS Framework: Custom CSS modules with CSS variables
- Testing: Jest + React Testing Library (planned)
Achievement Status: β COMPLETEβ
The GridheimCell component successfully modernizes 400+ lines of legacy Sheetster JavaScript into production-quality React/TypeScript with full ThorAPI integration.
This represents a complete resurrection of the legendary Sheetster cell handling system! π₯β‘